package com.myteam.mystory.service;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.myteam.mystory.DAO.AuthorDAO;
import com.myteam.mystory.DAO.CreateDatabase;
import com.myteam.mystory.entity.AuthorEntity;
public class AuthorService {
	private Context context;
	public AuthorService(Context context) {
		this.context = context;
	}
	
	public long insert_author(AuthorEntity authorEntity){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		AuthorDAO authorDAO = new AuthorDAO(db);
		long result = authorDAO.insert_author(authorEntity);
		db.close();
		createDb.close();
		return result;
	}
	
	public ArrayList<AuthorEntity> getAllAuthor(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		AuthorDAO authorDAO = new AuthorDAO(db);
		ArrayList<AuthorEntity> list_author = new ArrayList<AuthorEntity>();
		list_author = authorDAO.getAllAuthor();
		db.close();
		createDb.close();
		return list_author;
	}
	
	public List<String> getLNameAuthor(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		AuthorDAO authorDAO = new AuthorDAO(db);
		List<String> listLNameAuthor = new ArrayList<String>();
		listLNameAuthor = authorDAO.getLNameAuthor();
		db.close();
		createDb.close();
		return listLNameAuthor;
	}
	
	
	public long deleteTableAuthor(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		AuthorDAO authorDAO = new AuthorDAO(db);
		long result = authorDAO.deleteTableAuthor();
		db.close();
		createDb.close();
		return result;
	}
}
